package com.finance.cooperate.feature.reader;

import com.finance.cooperate.feature.base.ReaderImpl;
import com.finance.cooperate.feature.core.feature.FeatureDefinition;
import com.finance.cooperate.feature.core.feature.applist.AppListRetentiveTime;
import com.finance.cooperate.feature.core.feature.applist.AppListV1;
import com.finance.cooperate.feature.dto.CompositeAppCountDTO;
import com.finance.cooperate.feature.params.AppListParams;

import java.util.Map;

/**
 * @ClassName AppReader
 * @Description App 数据抽取
 * @Author shen
 * @Date 2022/5/26 22:44
 * @Modify ...
 */
public class AppReader extends ReaderImpl {

    @Override
    public Map<String, String> read(String userId) {

        AppListParams params = new AppListParams();
        params.setAppSetV1(AppListV1.app);
        params.setRetentiveSet(AppListRetentiveTime.app);

        CompositeAppCountDTO dto = appService.getCompositeAppCount(userId, params);

        super.put(FeatureDefinition.f_app_count, dto.getAppCount());
        
        super.put(FeatureDefinition.f_app_loan_top_10_count, dto.getLoanTop10Count());
        super.put(FeatureDefinition.f_app_loan_top_10_distance_submit_time_days_avg, dto.getLoanTop10DistanceSubmitTimeDaysAvg());
        super.put(FeatureDefinition.f_app_loan_top_10_distance_submit_time_days_max, dto.getLoanTop10DistanceSubmitTimeDaysMax());

        super.put(FeatureDefinition.f_app_loan_top_30_count, dto.getLoanTop30Count());
        super.put(FeatureDefinition.f_app_loan_top_30_distance_submit_time_days_avg, dto.getLoanTop30DistanceSubmitTimeDaysAvg());
        super.put(FeatureDefinition.f_app_loan_top_30_distance_submit_time_days_max, dto.getLoanTop30DistanceSubmitTimeDaysMax());

        super.put(FeatureDefinition.f_app_loan_top_60_count, dto.getLoanTop60Count());
        super.put(FeatureDefinition.f_app_loan_top_60_distance_submit_time_days_avg, dto.getLoanTop60DistanceSubmitTimeDaysAvg());
        super.put(FeatureDefinition.f_app_loan_top_60_distance_submit_time_days_max, dto.getLoanTop60DistanceSubmitTimeDaysMax());

        super.put(FeatureDefinition.f_app_nearly_1_months_app_count, dto.getNearly1MonthsAppCount());
        super.put(FeatureDefinition.f_app_nearly_2_months_app_count, dto.getNearly2MonthsAppCount());
        super.put(FeatureDefinition.f_app_nearly_3_months_app_count, dto.getNearly3MonthsAppCount());
        super.put(FeatureDefinition.f_app_nearly_1_months_app_percentage, dto.getNearly1MonthsAppPercentage());
        super.put(FeatureDefinition.f_app_nearly_2_months_app_percentage, dto.getNearly2MonthsAppPercentage());
        super.put(FeatureDefinition.f_app_nearly_3_months_app_percentage, dto.getNearly3MonthsAppPercentage());
        
        super.put(FeatureDefinition.f_app_first_app_install_days, dto.getFirstAppInstallDays());
        super.put(FeatureDefinition.f_app_last_app_install_days, dto.getLastAppInstallDays());

        super.put(FeatureDefinition.f_app_competition_level_v1, dto.getCompetitionAppLevelV1());
        super.put(FeatureDefinition.f_app_competition_level_1_count_v1, dto.getCompetitionAppLevel1CountV1());
        super.put(FeatureDefinition.f_app_competition_level_2_count_v1, dto.getCompetitionAppLevel2CountV1());
        super.put(FeatureDefinition.f_app_competition_level_3_count_v1, dto.getCompetitionAppLevel3CountV1());
        super.put(FeatureDefinition.f_app_competition_level_4_count_v1, dto.getCompetitionAppLevel4CountV1());
        super.put(FeatureDefinition.f_app_competition_level_5_count_v1, dto.getCompetitionAppLevel5CountV1());

        super.put(FeatureDefinition.f_app_competition_level_v2, dto.getCompetitionAppLevelV2());
        super.put(FeatureDefinition.f_app_competition_level_1_count_v2, dto.getCompetitionAppLevel1CountV2());
        super.put(FeatureDefinition.f_app_competition_level_2_count_v2, dto.getCompetitionAppLevel2CountV2());
        super.put(FeatureDefinition.f_app_competition_level_3_count_v2, dto.getCompetitionAppLevel3CountV2());
        super.put(FeatureDefinition.f_app_competition_level_4_count_v2, dto.getCompetitionAppLevel4CountV2());
        super.put(FeatureDefinition.f_app_competition_level_5_count_v2, dto.getCompetitionAppLevel5CountV2());

        super.put(FeatureDefinition.f_app_competition_level_3_to_5_count_v2, dto.getCompetitionAppLevel3To5CountV2());

        super.put(FeatureDefinition.f_app_has_chinese_count, dto.getHasChineseCount());



        Map<String, Long> installV1 = dto.getAppIsInstallV1();
        installV1.forEach((k, v) -> {
            String replace = k.replace(".", "_");
            super.put(FeatureDefinition.f_app_install_model_v1_.getValue() + replace, v);
        });

        Map<String, Long> timeV1 = dto.getAppInstallTimeV1();
        timeV1.forEach((k, v) -> {
            String replace = k.replace(".", "_");
            super.put(FeatureDefinition.f_app_time_model_v1_.getValue() + replace, v);
        });

        Map<String, Long> retentiveTime = dto.getAppRetentiveTime();
        retentiveTime.forEach((k, v) -> {
            String replace = k.replace(".", "_");
            super.put(FeatureDefinition.f_app_retentive_time_.getValue() + replace, v);
        });

        return super.getResult();
    }

}
